package staticinner;

import java.io.Serializable;

public class StaticInnerSingleton implements Serializable {

    private static class holder {
        private static final StaticInnerSingleton instance = new StaticInnerSingleton();
    }

    private StaticInnerSingleton(){
        if(holder.instance != null) {
            throw new RuntimeException("对象已存在，不允许创建多个实例");
        }
    }

    public final static StaticInnerSingleton getInstance() {
        return holder.instance;
    }

    public Object readResolve() {
        return holder.instance;
    }
}
